Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API functions for the other kinds of matrixes that a CRN ODE system can be factored into #1134

Open
wants to merge 30 commits into
base: master
Choose a base branch
from

Conversation

vyudu
Copy link
Collaborator

@vyudu vyudu commented Nov 23, 2024

Specifically laplacianmat, fluxmat, and massactionvector. Sorry about the terrible looking diff, I just split a lot of the more chemical reaction network-related tests (detailed/complex balance, deficiency theorems, concentration robustness) into a new file crn_theory.jl and added the tests for this to the bottom of the network_analysis.jl. (Realize I should have done the file splitting in a separate PR but was in too deep already). Closes #1132.

src/network_analysis.jl Outdated Show resolved Hide resolved
src/network_analysis.jl Outdated Show resolved Hide resolved
src/network_analysis.jl Outdated Show resolved Hide resolved
src/network_analysis.jl Outdated Show resolved Hide resolved
test/network_analysis/network_properties.jl Outdated Show resolved Hide resolved
test/network_analysis/network_properties.jl Outdated Show resolved Hide resolved
test/network_analysis/network_properties.jl Show resolved Hide resolved
@vyudu
Copy link
Collaborator Author

vyudu commented Nov 26, 2024

@isaacsas i think this is done mod the Documentation build thing

src/network_analysis.jl Outdated Show resolved Hide resolved
src/network_analysis.jl Outdated Show resolved Hide resolved

!isempty(pmap) && (rates = substitutevals(rn, pmap, parameters(rn), rates))
rcmap = reactioncomplexmap(rn); nc = length(rcmap); nr = length(rates)
mtype = eltype(rates) <: Symbolics.BasicSymbolic ? Num : eltype(rates)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be Num and not the unwrapped type?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it has to, doesn't seem like it's actually possible to have zeros in this matrix if the eltype is BasicSymbolic

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't it by type Any?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that better than being Num? I assumed more specific was better

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to return mixtures of Nums and non-Nums across different methods, so we should not re-wrap internal symbolics.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could I just wrap it in an Any when I return it? It's useful to have it be Num at least temporarily because I use zero(T) and one(T) in various places (and product over an empty Num[] returns 1, which is useful).

Copy link
Collaborator Author

@vyudu vyudu Dec 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this creates some issues for the sparse method (can't really do any arithmetic with a SparseMatrixCSC{Any, T} since zero(Any) is undefined). Would Union{Float64, BasicSymbolic} be okay? If not it might just be better to define two functions, one symbolic and one numeric

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to internally use Num I guess that is ok, but yeah, we should unwrap before returning to users for consistency.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about returning a Union as the element type?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually that doesn't work, nevermind, when you find the Laplacian matrix (D*K) type inference infers its eltype as Any anyway. Since it's the sparse matrix support that's causing the issue I think it might just be better to not allow the sparse kwarg for now

src/network_analysis.jl Outdated Show resolved Hide resolved
test/network_analysis/network_properties.jl Show resolved Hide resolved
test/network_analysis/network_properties.jl Show resolved Hide resolved
test/network_analysis/network_properties.jl Outdated Show resolved Hide resolved
Copy link
Member

@isaacsas isaacsas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vyudu just change the returning of Nums, and then if tests pass you are welcome to merge.


!isempty(pmap) && (rates = substitutevals(rn, pmap, parameters(rn), rates))
rcmap = reactioncomplexmap(rn); nc = length(rcmap); nr = length(rates)
mtype = eltype(rates) <: Symbolics.BasicSymbolic ? Num : eltype(rates)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to return mixtures of Nums and non-Nums across different methods, so we should not re-wrap internal symbolics.

@isaacsas
Copy link
Member

It looks like right now tests are failing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Further decompostion of a system of ODEs coming from mass-action chemical reaction networks
2 participants